<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = new Array("John","Mike","Inn");
        var arr1= [1,"Xiaoming",true];
        var num = arr.length;
        for(i=0;i<num;i++){
            document.write(arr1[i]," ");
        }
        document.write("<br/>");
        document.write(arr);
        document.write("<br/>");
        document.write("数组元素的增删改查");
        document.write("<br/>");
        document.write("一、修改：直接用数组名+下标。查找：直接用数组名+下标");
        
        document.write("<br/>");
        arr[1]="Messic";
        document.write(arr,"<br/>");
        document.write(arr[2],"<br/>");

        document.write("二、数组元素的增加1.push() 2.unshift() 3.concat()");
        document.write("<br/>");
        document.write("1.push()方法在数组尾部增加元素");
        arr.push("Zeo","Lisa");
        document.write(arr,"<br/>");

        document.write("2.unshift()方法在数组头部增加元素");
        arr.unshift("Xiaohong","Liming");
        document.write(arr,"<br/>");
        var arr2=["Summer","Brink"];

        document.write("3.concat()方连接多个数组：");
        var arr3=arr.concat(arr1,arr2)
        document.write(arr3,"<br/>");

        document.write("三、数组元素的删除1.delete 2.pop() 3.shift()");
        document.write("<br/>");
        document.write("1.delete运算符，数组名+下标:");
        delete arr3[1];
        document.write(arr3,"<br/>");
        var num = arr3.length;
        for(i=0;i<num;i++){
            document.write(arr3[i]," ");
        }
        document.write("<br/>");
        document.write("2.pop()删除数组最后一个元素，并返回该元素的值：");
        var a = arr3.pop();
        document.write(a,"<br/>");
        document.write(arr3,"<br/>");
        document.write("3.shift()删除数组第一个元素，并返回该元素的值：");
        var b = arr3.shift();
        document.write(b,"<br/>");
        document.write(arr3,"<br/>");
        arr3.shift();
        document.write(arr3,"<br/>");
        document.write("四、splice()方法用来对数组进行增、删操作");
        document.write("1.splice()如果有一个正参数，此参数为留下的前几个数组元素（从此参数下标开始删除之后的所有元素）：")
        arr3.splice(4);
        document.write(arr3,"<br/>");
        document.write("<br/>");
        document.write("2.splice()如果有两个正参数，删除以第一个参数为起始位置，第二个参数是要删除的元素个数：")
        var arr3=arr.concat(arr1,arr2)
        document.write(arr3,"<br/>");
        arr3.splice(3,2);
        document.write(arr3,"<br/>");
        document.write("3.splice()如果有一个负参数，：")
        document.write("<br/>");
        arr3.splice(-6,3);
        document.write(arr3,"<br/>");
        document.write("4.splice()如果有三个以上参数，先删除，再添加：")

        document.write("<br/>");
        arr3.splice(1,3,"Memo","Think");
        document.write(arr3,"<br/>");
        document.write("五、silce()方法提取字符串或数组的一部分");
        var fruits =["Banana","Orange","pear","Apple","Lemon","Mango"];
        document.write(fruits,"<br/>");
        var mybest = fruits.slice(2,5);//截取第2个，不到第5个元素
        document.write(mybest,"<br/>");
        var hisbest = fruits.slice(-4,-1);//截取倒数第4个，不到倒数第1个元素
        document.write(hisbest,"<br/>");
        var herbest = fruits.slice(-4);
        document.write(herbest,"<br/>");
        var str ="www.runoob.com!";
        document.write(str.slice(4)+"<br>");
        document.write(str.slice(4,10)+"<br>");
    </script>
    
</body>
</html>